#!/bin/bash

LOG_FILE=app.log

while getopts "a:l:o:" opt; do
  case $opt in
    a)
        APP_FILE=$OPTARG
        ;;
    l)
        LOG_FILE=$OPTARG
        ;;
    o)
        ARGS=$OPTARG
        ;;
    \?)
        echo "-a=jar文件 -l=log文件 -o=其他选项"
        exit 1
        ;;
  esac
done

if [ -z ${APP_FILE} ];
then
    echo "至少需要app参数"
    exit 1
elif [ ! -f ${APP_FILE} ];
then
    echo "app参数必须是一个文件"
    exit 1
fi

COMMAND="java -jar ${APP_FILE} ${ARGS}"
echo "COMMAND=${COMMAND}"
nohup ${COMMAND} > ${LOG_FILE} 2>&1 &